import sys
sys.path.append("/Users/johnmyers/dev/johnmyers-phd/teaching/aux-files")
import numpy as np
from plotting import plot_curve_animation, plot_surface
L = 10
blue = "#3399FF"
def u(x, t, n):
return np.sin(n * np.pi * x / L) * np.cos(n * np.pi * t / L)
def u1(x, t):
return u(x, t, 1)
x = np.linspace(0, L, 100)
t = np.linspace(0, 2 * L, 100)
plot_curve_animation(
functions=[u1],
colors=[blue],
title="Harmonic n=1",
x_vals=x,
y_vals=[-2, 2],
t_vals=t,
x_axis_label="x = position",
y_axis_label="u(x,t) = displacement",
)01 An introduction to PDEs, part 1
What is a partial differential equation (PDE)?
What are equations? What do we do with them?
We use equations to describe relationships between quantities.
Often, some quantities are known, while others are unknown and need to be determined.
We need to “solve for” the unknown quantities in terms of the known ones.
Beyond “algebraic” equations
Such equations are called differential equations because they involve differential operations.
This one happens to be an ordinary differential equation (ODE) because the unknown function \(y\) depends on a single variable \(x\).
- A synonym for “ordinary” (in this context) is “single-variable.”
ODEs appear everywhere in the real world.
The central definition
- A synonym for “partial” (in this context) is “multi-variable.”
The wave equation in 1 dimension
X, T = np.meshgrid(x, t)
plot_surface(
function=u1,
X=X,
Y=T,
x_axis_label="x = position",
y_axis_label="t = time",
z_axis_label="u(x,t) = displacement",
title="Harmonic n=1 over space and time",
)def u2(x, t):
return u(x, t, 2)
plot_curve_animation(
[u2],
labels=["Harmonic n=2"],
colors=[blue],
title="Harmonic n=2",
x_vals=x,
y_vals=[-2, 2],
t_vals=t,
x_axis_label="x = position",
y_axis_label="u(x,t) = displacement",
)plot_surface(
function=u2,
X=X,
Y=T,
x_axis_label="x = position",
y_axis_label="t = time",
z_axis_label="u(x,t) = displacement",
title="Harmonic n=2 over space and time",
)def u3(x, t):
return u(x, t, 3)
plot_curve_animation(
[u3],
labels=["Harmonic n=3"],
colors=[blue],
title="Harmonic n=3",
x_vals=x,
y_vals=[-2, 2],
t_vals=t,
x_axis_label="x = position",
y_axis_label="u(x,t) = displacement",
)plot_surface(
function=u3,
X=X,
Y=T,
x_axis_label="x = position",
y_axis_label="t = time",
z_axis_label="u(x,t) = displacement",
title="Harmonic n=3 over space and time",
)def superposition(x, t):
return u2(x, t) + u3(x, t)
plot_curve_animation(
[u2, u3, superposition],
labels=["n=2", "n=3", "superposition"],
colors=[blue, "#FF3399", "#33FF99"],
title="Superposition of harmonics n=2 and n=3",
x_vals=x,
y_vals=[-2, 2],
t_vals=t,
x_axis_label="x = position",
y_axis_label="u(x,t) = displacement"
)plot_surface(
function=superposition,
X=X,
Y=T,
x_axis_label="x = position",
y_axis_label="t = time",
z_axis_label="u(x,t) = displacement",
title="Superposition of harmonics n=2 and n=3 over space and time",
)The wave equation in 2 dimensions
import numpy as np
from plotting import plot_surface_animation
def u(x, y, t):
return (
np.sin(2 * np.pi * x) * np.sin(3 * np.pi * y) * np.sin(np.sqrt(13) * np.pi * t)
)
def u0(x, y):
return u(x, y, 0)
x = np.linspace(0, 1, 50)
y = np.linspace(0, 1, 50)
t_vals = np.linspace(0, 2, 200)
X, Y = np.meshgrid(x, y)
plot_surface_animation(
function=u,
init_function=u0,
X=X,
Y=Y,
z_range=[-1, 1],
t_vals=t_vals,
x_axis_label="x = position",
y_axis_label="y = position",
z_axis_label="u(x,y,t) = displacement",
title="Solution of 2D wave equation",
)